package com.kyzh.core.adapters.v3

import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.gushenge.core.beans.Game
import com.gushenge.core.dao.MMKVConsts
import com.kyzh.core.R
import com.kyzh.core.adapters.BiaoqianAdapter
import com.kyzh.core.databinding.ItemGameBorderBinding
import com.kyzh.core.extension.isNotNullOrEmpty
import com.kyzh.core.pager.gamedetail.GMGameDetailActivity1
import com.kyzh.core.pager.gamedetail.GameDetailActivity1
import com.kyzh.core.utils.setVisibility
import com.kyzh.core.utils.startGameDetailActivity

class GameListBorderAdapter(layout: Int, beans: ArrayList<Game>?) :
    BaseQuickAdapter<Game, BaseDataBindingHolder<ItemGameBorderBinding>>(layout, beans), LoadMoreModule {

    private var intentType = ""
    fun setIntentType(intentType: String) {
        this.intentType = intentType
    }

    override fun convert(holder: BaseDataBindingHolder<ItemGameBorderBinding>, item: Game) {
        holder.dataBinding?.let {
            it.data = item
            it.bq.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false)

            it.bq.adapter = BiaoqianAdapter(item.biaoqian)
            holder.itemView.setOnClickListener {
                if (intentType.isNotNullOrEmpty() && intentType == "gm") {
                    item.gid.let {
                        MMKVConsts.gid = item.gid
                        GMGameDetailActivity1.start(context, item.gid, type = "gm")
                    }
                } else {
                    if (item.game_type.isNotNullOrEmpty() && item.game_type == "1") {
                        item.gid.let {
                            MMKVConsts.gid = item.gid
                            GameDetailActivity1.start(context, item.gid, type = "gm")
                        }
                    } else {
                        context.startGameDetailActivity(item.gid)
                    }

                }
            }

            if (item.zhekou.isNullOrEmpty()) {
                it.btDiscount.setVisibility(false)
            } else {
                if (!item.zhekou.contains("折")) {
                    it.btDiscount.text = item.zhekou + "折"
                } else {
                    it.btDiscount.text = item.zhekou
                }
                it.btDiscount.setVisibility(true)
                if (item.zhekou.contains("10")) {
                    it.btDiscount.setVisibility(false)
                }
            }

        }
    }
}
